<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script>
    var p = new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve(888)
        }, 4000)
    })
    //当promise对象的状态变为finished成功时，会立即执行then和finally的回调
    //当promise对象的状态变为rejected失败时，会立即执行catch和finally的回调
    //不论最终promise对象的状态是finished还是rejected，finally的回调都会执行
    
    p.then((res) => {
        console.log('Promise状态会立即变为finished成功', res);
    }).catch((err) => {
        console.log('Promise状态会立即变为rejected失败', err);
    }).finally(()=>{
        console.log('promise对象的状态终止（结束）');
    })
</script>